package com.krain.ddbb.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.krain.corelibrary.widget.recyleview.BaseRecyclerViewAdapter;
import com.krain.ddbb.R;
import com.krain.ddbb.entity.UserIssueBean;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by ex-kuangxiaomin101 on 2016-01-13.
 */
public class UserIssueAdapter extends BaseRecyclerViewAdapter<UserIssueAdapter.ViewHolder> {

    private List<UserIssueBean> mList;
    private Context context;

    public UserIssueAdapter(List<UserIssueBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    public void refreshList(List<UserIssueBean> mList){
        this.mList = mList;
        notifyDataSetChanged();
    }

    public List<UserIssueBean> getList(){
        return mList;
    }

    @Override
    public ViewHolder getViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public View getItemView(int viewType, ViewGroup parent) {
        return  LayoutInflater.from(context).inflate(R.layout.item_order_list, parent, false);
    }

    @Override
    public Object getItem(int position)  {
        return mList.get(position);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.item_order_number.setText(spannableStringUtil("订单号    "+mList.get(position).getOrder_num(),7));
        holder.item_order_need.setText(spannableStringUtil("订单需求    "+mList.get(position).getDesc(),8));
        holder.item_order_money.setText(spannableStringUtil("服务价格    "+mList.get(position).getServer_price(),8));
        holder.item_order_time.setText(spannableStringUtil("发布时间    "+mList.get(position).getPublish_time(),8));
        if (mList.get(position).getStatus() == UserIssueBean.STATUS_COMPLETE){
            holder.item_order_status.setText("已完成");
        }else if (mList.get(position).getStatus() == UserIssueBean.STATUS_CANCEL){
            holder.item_order_status.setText("已取消");
        }else if (mList.get(position).getStatus() == UserIssueBean.STATUS_WAIT_COMMENT){
            holder.item_order_status.setText("待评论");
        }else if (mList.get(position).getStatus() == UserIssueBean.STATUS_WAIT_PAY){
            holder.item_order_status.setText("待付款");
        }else if (mList.get(position).getStatus() == UserIssueBean.STATUS_WAIT_SERVICE){
            holder.item_order_status.setText("待服务");
        }else if (mList.get(position).getStatus() == UserIssueBean.STATUS_WAIT_CONFIRM){
            holder.item_order_status.setText("待确认");
        }else  holder.item_order_status.setText("待抢单");

    }


    SpannableString spannableStringUtil(String str,int start){
        SpannableString string = new SpannableString(str);
        string.setSpan(new ForegroundColorSpan(Color.BLACK),start,string.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        return string;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public  class ViewHolder extends RecyclerView.ViewHolder {
        public TextView item_order_number;
        public TextView item_order_need;
        public TextView item_order_money;
        public TextView item_order_time;
        public TextView item_order_status;

        public ViewHolder(View itemView) {
            super(itemView);
            item_order_number = (TextView)itemView.findViewById(R.id.item_order_list_tv_number);
            item_order_need = (TextView)itemView.findViewById(R.id.item_order_list_tv_need);
            item_order_money = (TextView)itemView.findViewById(R.id.item_order_list_tv_money);
            item_order_time = (TextView)itemView.findViewById(R.id.item_order_list_tv_time);
            item_order_status = (TextView)itemView.findViewById(R.id.item_order_list_tv_status);
        }
    }
}
